import Vue from 'vue'
import store from '../store'
// 指令
Vue.directive('hasPermission', {
  inserted (el, binding, vNode) {
    const {value} = binding
    // eslint-disable-next-line camelcase
    const all_permission = '*/*/*/'
    var arr = []
    const permissions = store.state.user.permissions
    arr.push(permissions.permissions[0])
    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value
      const hasPermissions = arr.some(permission => {
        // eslint-disable-next-line camelcase
        return all_permission === permission || permissionFlag.includes(permission)
      })
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error('请设置操作权限标签值')
    }
  }
})
